package com.wangxin.model;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.jfinal.plugin.activerecord.ICallback;

public class SerialProcedure implements ICallback{
	
	private Logger log = Logger.getLogger(this.getClass());
	
	private String cxm;
	
	private String serial;

	public SerialProcedure(String cxm){
		this.cxm = cxm;
	}
	
	public String getSerial() {
		return serial;
	}

	@Override
	public Object call(Connection conn) throws SQLException {
		CallableStatement proc = null; 
		try {
			proc = conn.prepareCall("{ call P_GET_SERIAL(?,?) }");
			proc.setString(1, cxm);
			proc.registerOutParameter(2, java.sql.Types.VARCHAR);
			proc.execute();
			serial = proc.getString(2);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
		} finally {
			if(proc!=null){
				proc.close();
			}
		}
		return serial;
	}

}
